package com.dofast.bt.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dofast.bt.R;
import com.dofast.bt.base.BaseApplication;
import com.dofast.bt.bean.AttentionBean;
import com.dofast.bt.bean.ShopBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * username:Created by hsj on 2016/12/22 0022.
 * class：
 * 类描述：收藏的店铺
 */

public class CollectStoreListAdapter extends BaseAdapter {
    private List<AttentionBean> list = new ArrayList<AttentionBean>();

    public CollectStoreListAdapter(List<AttentionBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            convertView = LayoutInflater.from(BaseApplication.getInstance().getApplicationContext()).inflate(R.layout.item_collect_goods, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvPrice.setVisibility(View.GONE);

        //店铺名称
        ShopBean shopBean = list.get(position).getShop();
        if (shopBean != null) {
            holder.tvName.setText(shopBean.getName());
            //店铺头像
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(shopBean.getImg_head()).placeholder(R.mipmap.head_store1).into(holder.ivPhoto);
        }
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;
        @BindView(R.id.iv_dot)
        ImageView ivDot;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.ll_delete)
        LinearLayout llDelete;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
